package Study.company;

import java.util.Arrays;

public class Qulck {
    public static void main(String[] args) {
        int[] arr = {36, 21, 66, 15, 27, 5, 46, 94, 13, 45, 6};
        quicksort(arr,0, arr.length - 1);
        System.out.println(Arrays.toString(arr));

    }
    public static void quicksort(int[] arr,int low,int high){
        if (low >= high){
            return;
        }
        int jizhun = arr[low];
        int i = low;
        int j = high;
        while (i != j){
            //找到比基准值小的下标
            while (j > i && arr[j] >=jizhun){
                j--;
            }
            //找到比基准值大的下标
            while (j > i && arr[i] <= jizhun){
                i++;
            }
            if (i < j){
                arr[j] = arr[i] ^ arr[j];
                arr[i] = arr[i] ^ arr[j];
                arr[j] = arr[i] ^ arr[j];
            }
        }
        if (arr[i] < jizhun){
            arr[low] = arr[i];
            arr[i] = jizhun;
        }
        //数组以i下标分成左边和右边两部分 i 左边 小于 基准值  i 右边比基准值大
        //排序左边
        quicksort(arr,low,i - 1);
        //排序右边\
        quicksort(arr,i + 1,high);
    }
}
